﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Silvery.Scene;

namespace Sample03_Scene
{
    
    public partial class SceneA : UserControl, ISceneElement
	{
		public SceneA()
		{
			// Required to initialize variables
			InitializeComponent();
           
        }

        public void OnUpdata(IScene sender, Silvery.ITimer CallTimer)
        {
            if (sender.Hero != null)
            {
                for (int i = rects.Children.Count - 1; i >= 0; i--)
                {
                    var r = rects.Children[i] as Rectangle;
                    GetRectangleRect(r);
                    if (rRect.Contains(sender.Hero.Position))
                    {
                        var str = (r.Tag as string);
                        (this.Resources[str] as Storyboard).Begin() ;
                        rects.Children.RemoveAt(i);
                        break;
                    }
                }
            }
        
        }
        Rect rRect = new Rect();
        Rect GetRectangleRect(Rectangle rect)
        {
            rRect.X = Canvas.GetLeft(rect);
            rRect.Y = Canvas.GetTop(rect);
            rRect.Width = rect.Width;
            rRect.Height = rect.Height;
            return rRect;
        }
    }
}